﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CarInfor.DAL
{
    public class AlertSetting
    {
        #region 属性定义


        /// <summary>
        /// 年检开始
        /// </summary>
        private int yearCheckAlertB;
        public int YearCheckAlertB
        {
            get { return yearCheckAlertB; }
            set { yearCheckAlertB = value; }
        }

        /// <summary>
        /// 年检结束
        /// </summary>
        private int yearCheckAlertE;
        public int YearCheckAlertE
        {
            get { return yearCheckAlertE; }
            set { yearCheckAlertE = value; }
        }

        /// <summary>
        /// 交强险开始
        /// </summary>
        private int insuranceJQAlertB;
        public int InsurancJQAlertB
        {
            get { return insuranceJQAlertB; }
            set { insuranceJQAlertB = value; }
        }
        /// <summary>
        /// 交强险结束
        /// </summary>
        private int insuranceJQAlertE;
        public int InsurancJQAlertE
        {
            get { return insuranceJQAlertE; }
            set { insuranceJQAlertE = value; }
        }

        /// <summary>
        /// 交强险开始
        /// </summary>
        private int insuranceBussAlertB;
        public int InsurancBussAlertB
        {
            get { return insuranceBussAlertB; }
            set { insuranceBussAlertB = value; }
        }
        /// <summary>
        /// 交强险结束
        /// </summary>
        private int insuranceBussAlertE;
        public int InsurancBussAlertE
        {
            get { return insuranceBussAlertE; }
            set { insuranceBussAlertE = value; }
        }
        #endregion

        #region 方法
        /// <summary>
        /// 无条件查询
        /// </summary>
        public DataTable Query()
        {
            DataSet ds = null;
            try
            {
                DB db = new DB();
                ds = db.GetSqlDataSet("Select * from Alertsettings");
            }
            catch (Exception e)
            {
                throw (e);
            }
            return ds.Tables[0];
        }

        /// <summary>
        /// 无条件查询
        /// </summary>
        public void GetSetting()
        {
            DataSet ds = null;
            try
            {
                DB db = new DB();
                ds = db.GetSqlDataSet("Select * from Alertsettings");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    yearCheckAlertB = int.Parse(ds.Tables[0].Rows[0]["yearCheckAlertB"].ToString());
                    yearCheckAlertE = int.Parse(ds.Tables[0].Rows[0]["yearCheckAlertE"].ToString());
                    insuranceJQAlertB = int.Parse(ds.Tables[0].Rows[0]["insuranceJQAlertB"].ToString());
                    insuranceJQAlertE = int.Parse(ds.Tables[0].Rows[0]["insuranceJQAlertE"].ToString());
                    insuranceBussAlertB = int.Parse(ds.Tables[0].Rows[0]["insuranceBussAlertB"].ToString());
                    insuranceBussAlertE = int.Parse(ds.Tables[0].Rows[0]["insuranceBussAlertE"].ToString());
                }

            }
            catch (Exception e)
            {
                throw (e);
            }
        }

        /// <summary>
        ///添加一条记录
        /// </summary>
        public int Insert()
        {
            StringBuilder sql = new StringBuilder();
            DB db = new DB();
            try
            {
                sql.Append("INSERT into [AlertSettings]");
                sql.Append("([yearCheckAlertB],[yearCheckAlertE],[insuranceJQAlertB],[insuranceJQAlertE],[insuranceBussAlertB],[insuranceBussAlertE]) ");
                sql.Append(" VALUES(");
                sql.Append(yearCheckAlertB);
                sql.Append("," + yearCheckAlertE);
                sql.Append("," + insuranceJQAlertB);
                sql.Append("," + insuranceJQAlertE);
                sql.Append("," + insuranceBussAlertB);
                sql.Append("," + insuranceBussAlertE);
                sql.Append(")");
            }
            catch (Exception e)
            {
                throw (e);
            }
            return db.ExecuteSql(sql.ToString());
        }

        /// <summary>
        /// 要求在调用IsDelete（）后使用
        /// 返回为true时，表示删除成功
        /// 返回为false时，表示删除失败
        /// </summary>
        public bool Delete()
        {
            StringBuilder sql = new StringBuilder();
            DB db = new DB();
            try
            {
                sql.Append(" DELETE FROM [AlertSettings] ");
                db.ExecuteSql(sql.ToString());
            }
            catch (Exception e)
            {
                throw (e);
            }
            return true;
        }



        #endregion
    }
}